using Microsoft.AspNetCore.Mvc;
using ZR.Model.BaseManage.Dto;
using ZR.Model.BaseManage;
using ZR.Service.BaseManage.IBaseManageService;
using ZR.Admin.WebApi.Filters;

//创建时间：2025-04-20
namespace ZR.Admin.WebApi.Controllers.BaseManage
{
    /// <summary>
    /// 供应商信息
    /// </summary>
    [Verify]
    [Route("BaseManage/BaseSupplier")]
    public class BaseSupplierController : BaseController
    {
        /// <summary>
        /// 供应商信息接口
        /// </summary>
        private readonly IBaseSupplierService _BaseSupplierService;

        public BaseSupplierController(IBaseSupplierService BaseSupplierService)
        {
            _BaseSupplierService = BaseSupplierService;
        }

        /// <summary>
        /// 查询供应商信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "base:supplier:list")]
        public IActionResult PageBaseSupplier([FromQuery] BaseSupplierQueryDto parm)
        {
            var response = _BaseSupplierService.GetPageList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询供应商信息详情
        /// </summary>
        /// <param name="SupplierId"></param>
        /// <returns></returns>
        [HttpGet("{SupplierId}")]
        [ActionPermissionFilter(Permission = "base:supplier:query")]
        public IActionResult GetBaseSupplier(string SupplierId)
        {
            var response = _BaseSupplierService.GetInfo(SupplierId);
            
            var info = response.Adapt<BaseSupplierDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加供应商信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "base:supplier:add")]
        [Log(Title = "供应商信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddBaseSupplier([FromBody] BaseSupplierDto parm)
        {
            var modal = parm.Adapt<BaseSupplier>().ToCreate(HttpContext);

            var response = _BaseSupplierService.AddBaseSupplier(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新供应商信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "base:supplier:edit")]
        [Log(Title = "供应商信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateBaseSupplier([FromBody] BaseSupplierDto parm)
        {
            var modal = parm.Adapt<BaseSupplier>().ToUpdate(HttpContext);
            var response = _BaseSupplierService.UpdateBaseSupplier(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除供应商信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "base:supplier:delete")]
        [Log(Title = "供应商信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteBaseSupplier([FromBody] string[] ids)
        {
            return ToResponse(_BaseSupplierService.Delete(ids));
        }

    }
}